package com.hckjsec.cloud.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import com.hckjsec.common.utils.StringUtils;
import com.hckjsec.common.utils.sign.Base64Converter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.cloud.domain.AppletsPublicTeam;
import com.hckjsec.cloud.service.IAppletsPublicTeamService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 团队介绍主Controller
 * 
 * @author cyt
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/system/team")
public class AppletsPublicTeamController extends BaseController
{
    @Autowired
    private IAppletsPublicTeamService appletsPublicTeamService;

    /**
     * 查询团队介绍主列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletsPublicTeam appletsPublicTeam)
    {
        startPage();
        appletsPublicTeam.setDeptId(SecurityUtils.getDeptId());
        List<AppletsPublicTeam> list = appletsPublicTeamService.selectAppletsPublicTeamList(appletsPublicTeam);
        return getDataTable(list);
    }

    /**
     * 导出团队介绍主列表
     */
    @Log(title = "团队介绍主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsPublicTeam appletsPublicTeam)
    {
        appletsPublicTeam.setDeptId(SecurityUtils.getDeptId());
        List<AppletsPublicTeam> list = appletsPublicTeamService.selectAppletsPublicTeamList(appletsPublicTeam);
        ExcelUtil<AppletsPublicTeam> util = new ExcelUtil<AppletsPublicTeam>(AppletsPublicTeam.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 获取团队介绍主详细信息
     */
    @GetMapping(value = "/{teamId}")
    public AjaxResult getInfo(@PathVariable("teamId") Long teamId)
    {
        return AjaxResult.success(appletsPublicTeamService.selectAppletsPublicTeamById(teamId));
    }

    /**
     * 新增团队介绍主
     */
    @Log(title = "团队介绍主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletsPublicTeam appletsPublicTeam)
    {
        appletsPublicTeam.setDeptId(SecurityUtils.getDeptId());
        appletsPublicTeam.setOperator(SecurityUtils.getUserId());
        if (!"".equals(StringUtils.isHcNull(appletsPublicTeam.getContent(),""))){//解密
            appletsPublicTeam.setContent(Base64Converter.decode(appletsPublicTeam.getContent()));
        }else{
            appletsPublicTeam.setContent(appletsPublicTeam.getContent());
        }
        return toAjax(appletsPublicTeamService.insertAppletsPublicTeam(appletsPublicTeam));
    }

    /**
     * 修改团队介绍主
     */
    @Log(title = "团队介绍主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsPublicTeam appletsPublicTeam)
    {
        if (!"".equals(StringUtils.isHcNull(appletsPublicTeam.getContent(),""))){//解密
            appletsPublicTeam.setContent(Base64Converter.decode(appletsPublicTeam.getContent()));
        }else{
            appletsPublicTeam.setContent(appletsPublicTeam.getContent());
        }
        return toAjax(appletsPublicTeamService.updateAppletsPublicTeam(appletsPublicTeam));
    }

    /**
     * 删除团队介绍主
     */
    @Log(title = "团队介绍主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teamIds}")
    public AjaxResult remove(@PathVariable Long[] teamIds)
    {
        return toAjax(appletsPublicTeamService.deleteAppletsPublicTeamByIds(teamIds));
    }
}
